Sprint

Section: Miscellaneous Library Functions (3X)
Updated: 29 May 1992
Index Return to Main Contents
 

NAME

Sprint -- formatted stream output  

SYNOPSIS

int Sprint( fd, format [ , ... ] )
int fd ;
char *format ;
 

DESCRIPTION

Sprint() provides formatted output conversion. The formatting is controlled by the format argument. All characters in format that do not specify a conversion are printed. A conversion is specified by a '%' followed by a string that ends with a conversion type character. The string may contain flags, a field width, a precision, and a modifier. The possible flags are '-', '+', ' ', '0', and '#'.

Possible flags (more that one can be specified and they can be in any order):

'-'
specifies left adjustment of the converted argument. The default is right adjustment. This flag is meaningful only if a field width is specified.
'+'
specifies that a number will always have a sign as a prefix (this forces a '+' sign to appear if the number is positive).
' '
prefixes a space to the number if the number has not a sign (therefore the '+' flag overrides this flag).
'#'
The meaning of '#' depends on the conversion type character: for o conversions the first digit will be 0; for x or X conversions 0x or 0X respectively will be prefixed to the number (if it is not zero); for e, E, f, g, and G conversions the number will always have a decimal point.

The field width is specified by a number. This number indicates the minimum width for the field. A '*' may be used instead of the number. In that case the width is the value of the next argument which should be an int. A negative width value specifies left adjustment with a width equal to the absolute width value.

A precision is specified by a '.' followed by a number. The meaning of the precision depends on the type conversion character. For a string conversion, precision determines how many characters are printed from the string. For integer conversions, precision determines the number of digits used to print the number (zero padding is done if the precision exceeds the length of the number). For floating point conversions, precision determines the number of digits after the decimal point (e, E, f) or the number of significant digits (g, G). A '*' may be used instead of a number to specify the precision. In that case the precision is the value of the next argument which should be an int. The behavior of Sprint() is undefined if the precision is negative.

The length modifier is l and indicates that the argument is a long integer.

The type conversion characters are: d, i, o, x, X, u, c, s, f, e, E, g, G, p, n, %. For floating point conversions the argument should be of type double.

d,i
specify signed decimal conversion.
u
specifies unsigned decimal conversion.
o
specifies octal conversion.
x,X
specify hexadecimal conversion. For x the hex digits used are 0123456789abcdef. For X the hex digits used are 0123456789ABCDEF. There is no leading 0x or 0X (use the '#' flag for that).
c
specifies character conversion; the argument should be of type char.
s
specifies string conversion; the argument should be of type char *.
f
specifies conversion to the form [-]ddd.dddd. The number of digits after the decimal point depends on precision; the default is 6. If the precision is 0, the decimal point is not printed (this can be overriden with the '#' flag). e,E specify conversion to the form [-]ddd.dddd[eE][+-]ddd. The number of digits after the decimal point depends on precision; the default is 6. If the precision is 0, the decimal point is not printed (this can be overriden with the '#' flag). The exponent is at least 2 digit wide.
g,G
specify a conversion using the e,E format respectively if the exponent is less than -4 or greater than or equal to the precision; otherwise the f format is used.
p
is used to print pointers (type void *, or char * if the compiler does not support the former).
n
expects a int * argument and puts in that integer the number of characters already printed by this call.
%
is used to print a %.

If an unknown conversion character is specified, the percent sign followed by that character will be printed.  

RETURN VALUE

If no error occured, Sprint() returns the number of characters printed. In case of error, it returns SIO_ERR.  

BUGS

This is a list of differences between Sprint() and the ANSI C Standard printf():

Sprint() does not support non-removal of trailing zeroes for g and G conversions when the '#' flag is used.

Sprint() does not support the h and L modifiers.

The current implementation assumes that sizeof(int)==sizeof(long).

Sprint() supports "%p" only if sizeof(pointer)<=sizeof(int).


 

Index

NAME
SYNOPSIS
DESCRIPTION
RETURN VALUE
BUGS

This document was created by man2html, using the manual pages.
Time: 06:35:40 GMT, May 19, 2025